const { response } = require('express');
const express = require('express');

const bodyParser = require('body-parser');


const app = express();
app.use(bodyParser.urlencoded({extended:false}));
app.use(function(request, response, next){
    response.set('Access-Control-Allow-Origin','*');
    response.set('Access-Control-Allow-Headers','*')
    next();
})

app.get('/server',(request, response)=>{
    response.send('server run');
})

app.get('/get', (request,response)=>{
    console.log('query',request.query);
    console.log('headers',request.headers);
    response.send('get server');
})

app.post('/post', (request,response)=>{
    console.log('body',request.body);
    response.send('post server');
})

app.get('/json',(request, response)=>{
    let data = {
        errno:1,
        errmsg:'用户名已存在'
    }
    response.json(data);
})
app.listen(8080,()=>{
    console.log('server run at 8080');
})